package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.OrderSettingListService;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ordersettinglist")
public class OrderSettingListController {

    @Reference
    private OrderSettingListService orderSettingListService;
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = orderSettingListService.findPage(queryPageBean);
        return pageResult;
        /*dfssfsf*/
     /*  Map map = new HashMap();
       map.put("id",17);
       map.put("name","xiaohong");
       map.put("orderDate","2018-08-08");
       map.put("phoneNumber","15111111111" );
       map.put("orderStatus","未到诊");
       map.put("orderType","微信预约");
        List list = new ArrayList();
        list.add(map);
        PageResult pageResult = new PageResult(1L, list);
        return pageResult;*/
    }

    @GetMapping("/orderConfirm")
    public Result orderConfirm(Integer id){
        try{
            orderSettingListService.orderConfirm(id);
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDERCONFIRM_FAIL);
        }
        return new Result(true,MessageConstant.ORDERCONFIRM_SUCCESS );
    }

    @GetMapping("/orderCancel")
    public Result orderCancel(Integer id){
        try{
            orderSettingListService.orderCancel(id);
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDERCANCEL_FAIL);
        }
        return new Result(true,MessageConstant.ORDERCANCEL_SUCCESS );
    }
    @PostMapping("/add")
    public Result add(@RequestBody Map map, Integer[] setmealIds){
        Result result = new Result(false,MessageConstant.ADD_CHECKGROUP_FAIL );
        try{
            map.put("orderType", Order.ORDERTYPE_TELEPHONE );
            result = orderSettingListService.add(map,setmealIds);
            return result;
        }catch(Exception e){
            e.printStackTrace();
            return result;
        }
    }
}
